package com.lyr.thread4;

public class MyThread extends Thread {

    public MyThread(String name) {
        super(name);
    }

    @Override
    public void run() {
        for (int i=1;i<11;++i){
            System.out.println(i+": "+this.getName());

            try {
                if (i==3){

                    // yield方法：调用yield方法，
                    // 当前线程暂时主动放弃本次cpu资源，让其他线程执行；
                    Thread.yield();
                }
                // 线程休眠时间
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
